 package com.huidao.servlet.buyer;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.huidao.entity.Goods;
import com.huidao.entity.Order;
import com.huidao.entity.Shoppingcart;
import com.huidao.entity.User;
import com.huidao.service.buyer.OrderService;
import com.huidao.service.buyer.OrderServiceImp;

/**
 * Servlet implementation class AddOrderServlet
 */
public class AddOrderServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddOrderServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		OrderService os = new OrderServiceImp();
		Order od = new Order();
		od.setGoods_num(Integer.parseInt(request.getParameter("goods_num")));
		System.out.println(request.getParameter("goods_num"));
		User user = new User();
		user.setUserId(Long.parseLong(request.getParameter("UserId")));
		od.setUser(user);
		Goods goods = new Goods();
		goods.setGid(Long.parseLong(request.getParameter("gid")));
		goods.setgAccount(Integer.parseInt(request.getParameter("gAccount")));
		od.setGoods(goods);
		String data = os.addOrder(od);
		if(data==""){
			response.sendRedirect("GetBuyerGoodsListServlet");
		}else{
			response.getWriter().print(data);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
